package 第二章数据结构.栈.id828模拟栈;

import java.util.Scanner;

public class Main {
    public static void main(String[]args){
        //处理输入
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        scanner.nextLine();
        MyStack stack = new MyStack();
        while (m -- > 0){
            String s = scanner.nextLine();
            String[]ops = s.split(" ");
            if(ops[0].equals("push")){
                stack.push(Integer.parseInt(ops[1]));
            }else if(ops[0].equals("pop")){
                stack.pop();
            }else if(ops[0].equals("empty")){
                boolean isEmpty = stack.empty();
                if(isEmpty)System.out.println("YES");
                else System.out.println("NO");
            }else {
                System.out.println(stack.query());
            }
        }
    }
    //封装MyStack类
    static class MyStack{
        //从下标1开始
        static int[] arrays ;
        //指向栈顶
        static int top = 0;
        MyStack(){
            arrays = new int[100001];
        }
        //压栈
        static void push(int x){
            top++;
            arrays[top] = x;
        }
        //出栈
        static void pop(){
            top--;
        }
        //查询栈顶元素
        static int query(){
            return arrays[top];
        }
        //是否为空
        static boolean empty(){
            return top == 0;
        }
    }
}
